﻿namespace eProject.ViewModel.Commands
{
    public class CreateEmployeeCommand : ICommand
    {
        private readonly CommonManager _manager;
        private readonly string _name;
        private readonly string _surname;
        private readonly string _phone;
        private readonly string _email;

        private bool _isCanceled;
        private bool _isExecuted;

        public CreateEmployeeCommand(CommonManager manager, string name, string surname, string phone, string email)
        {
            _manager = manager;
            _name = name;
            _surname = surname;
            _phone = phone;
            _email = email;
        }

        public void Execute()
        {
            if (_isExecuted) return;
            _manager.CreateEmployee(_name, _surname, _phone, _email);
            _isExecuted = true;
            _isCanceled = false;
        }

        public void Unexecute()
        {
            if (_isCanceled) return;
            var empl = _manager.GetEmployee(_email);
            _manager.DeleteEmployee(empl);
            _isCanceled = true;
            _isExecuted = false;
        }
    }
}
